﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;

namespace TP2
{
    public partial class EditCreditForm : Form
    {
        int id_client;
        int number;
        float procent;
        string client_type;
        int credit;
        DateTime finish_date;
        LoanForm loan_form;
        System.DateTime date = new DateTime();
        public EditCreditForm(int idClient, int Number, float Procent, string clienType, DateTime finishDate,int Credit, LoanForm loanFr)
        {
            id_client = idClient;
            number = Number;
            procent = Procent;
            client_type = clienType;
            finish_date = finishDate;
            credit = Credit;
            date = System.DateTime.Now;
            loan_form = loanFr;
            InitializeComponent();
        }

        private void EditCreditForm_Load(object sender, EventArgs e)
        {
            label2.Text = credit.ToString();
            labelProcent.Text = procent.ToString();
            textBoxCredit.Text = "0";
            labelPeriod.Text = ((finish_date.Year - date.Year) * 12 + (finish_date.Month - date.Month)).ToString();

        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            try
            {
                int vznos = Convert.ToInt32(textBoxCredit.Text);
                DBWorkClass dbWork = new DBWorkClass();
                dbWork.UpdateLoan(vznos, credit, finish_date, number);
                loan_form.RefreshTable();
                this.Close();
            }
            catch (FormatException) { MessageBox.Show("ошибка во входных данных"); }
        }
    }
}
